
* Reset frames
frame reset

* Open data and set background scheme
use  "INSERTPATH/data_S3.dta", clear // Remember to update file directory ("INSERTPATH")
cd "INSERTPATH" // Remember to update file directory ("INSERTPATH")
set scheme plotplain

* make & rescale variables
gen affect_inparty = (inparty_affect/10)
gen affect_outparty = (outparty_affect/10)
gen affective_polarization = (affect_inparty - affect_outparty)
gen election = (pei-1)/4


* Fig 5, S3:
frame rename default data

qui reg outparty_voting i.D i.P if M==0, rob			// Congenial source
mat A1 = r(table)
qui reg outparty_voting i.D i.P if M==1, rob			// Uncongenial source
mat A2 = r(table)

qui reg affect_inparty i.D i.P if M==0, rob				// Congenial Source
mat B1 = r(table)
qui reg affect_inparty i.D i.P if M==1, rob				// Uncongenial Source
mat B2 = r(table)


qui reg affect_outparty i.D i.P if M==0, rob
mat C1 = r(table)
qui reg affect_outparty i.D i.P if M==1, rob
mat C2 = r(table)


qui reg affective_polarization i.D i.P if M==0, rob
mat D1 = r(table)
qui reg affective_polarization i.D i.P if M==1, rob
mat D2 = r(table)


mat H = 0,.86,A1[1,2],A1[5,2],A1[6,2],0\	///
		0,.84,A2[1,2],A2[5,2],A2[6,2],1\	///
		1,.81,B1[1,2],B1[5,2],B1[6,2],0\ 	///
		1,.79,B2[1,2],B2[5,2],B2[6,2],1\	///
		2,.76,C1[1,2],C1[5,2],C1[6,2],0\ 	///
		2,.74,C2[1,2],C2[5,2],C2[6,2],1\ 	///
		3,.71,D1[1,2],D1[5,2],D1[6,2],0\ 	///
		3,.69,D2[1,2],D2[5,2],D2[6,2],1
		
		


* make plot 3A: 
frame create plot1
cwf plot1		
svmat H
rename H1 outcome
rename H2 Ypos
rename H3 b
rename H4 ll
rename H5 ul
rename H6 source					// 0 = congenial, 1 = uncongenial





tw ///
	(rspike ll ul Ypos, horizontal lcolor(black)) ///
	(scatter Ypos b if source==0, msym(O) mc(black) msize(med) mlabel(b) mlabformat(%5.2fc) mlabposition(12) mlabsize(vsmall)) ///
	(scatter Ypos b if source==1, msym(O) mc(black) mfcolor(white) msize(med) mlabel(b) mlabformat(%5.2fc) mlabposition(6) mlabsize(vsmall)) ///
	, yscale(range(.68 .87) lc(none)) ytit("") ///
	ylab(.85 "Out-Party Voting" .8 "In-Party Affect" .75 "Out-Party Affect" .7 "Affective Polarization", notick glpattern(solid) glcolor(gs14%50)) ///
	xtit("Treatment Effect Estimate", size(small)) xscale(range(-.2 .15) lc(none)) xlab(-.2 -.1 0 .1 .2, notick glpattern(solid) glcolor(gs14%50)) xline(0) ///
	legend(order(2 "Congenial" 3 "Uncongenial" )) plotregion(lcolor(black) lwidth(medium)) ///
	title("In-Party Cheating", size(small) justification(left) pos(11)) ///
	name(S3_affect, replace)
	
	

graph display, xsize(5) ysize(2.1) scale(2.2)	

graph export "S3_Fig3.pdf", as(pdf) replace	
